package jmine.tec.utils.collection;

import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedList;

import jmine.tec.utils.IterationStep;

/**
 * {@link IterationStep} that collect the entries iterated.
 * 
 * @author takeshi
 * @version 14/08/2007
 * @param <E> the type
 */
public final class CollectEntriesIterationStep<E> implements IterationStep<E>, Serializable {
    private static final long serialVersionUID = -6750133627181762398L;

    private final Collection<E> collection;

    /**
     * C'tor
     */
    public CollectEntriesIterationStep() {
        this(new LinkedList<E>());
    }

    /**
     * C'tor
     * 
     * @param collections the {@link Collection} to collect on
     */
    public CollectEntriesIterationStep(final Collection<E> collections) {
        this.collection = collections;
    }

    /**
     * @return the collection
     */
    public Collection<E> getCollection() {
        return this.collection;
    }

    /**
     * @param it the element
     * @return boolean
     * @see br.com.maps.util.IterationStep#nextStep(java.lang.Object)
     */
    public boolean nextStep(final E it) {
        return this.collection.add(it);
    }
}
